"""
序列化
"""
from rest_framework import serializers

from .models import Goods, GoodsCategory


class CategorySerializer3(serializers.ModelSerializer):
    """
    商品分类序列化3
    """
    class Meta:
        model = GoodsCategory
        fields = "__all__"  # 调用所有字段


class CategorySerializer2(serializers.ModelSerializer):
    """
    商品分类序列化2
    """
    seb_cat = CategorySerializer3(many=True)  # 当有多条数据时，一定要加many=True

    class Meta:
        model = GoodsCategory
        fields = "__all__"  # 调用所有字段


class CategorySerializer(serializers.ModelSerializer):
    """
    商品分类序列化1
    """
    seb_cat = CategorySerializer2(many=True)  # 当有多条数据时，一定要加many=True

    class Meta:
        model = GoodsCategory
        fields = "__all__"  # 调用所有字段


class GoodsSerializer(serializers.ModelSerializer):
    """
    商品序列化
    """
    category = CategorySerializer()  # 使用 Serializer 嵌套，这样可以使外键完整地展现出来

    class Meta:
        model = Goods
        fields = "__all__"  # 调用所有字段
        # fields = ('name', 'add_time', 'click_num', 'market_price')  # 局部调用字段